package mall

import (
	"errors"
	"gorm.io/gorm"
	"newbeemallStudyProject/global"
	"newbeemallStudyProject/model/mall"
)

type MallUserTokenService struct {
}

func (m *MallUserTokenService) ValidToken(token string) (err error, userToken mall.MallUserToken) {
	var mallUserToken mall.MallUserToken
	if errors.Is(global.GVA_DB.Where("token = ?", token).First(&mallUserToken).Error, gorm.ErrRecordNotFound) {
		return errors.New("token不存在。。。"), mallUserToken
	}
	return
}

func (m *MallUserTokenService) DeleteToken(token string) (err error) {
	err = global.GVA_DB.Where("token = ?", token).Delete(mall.MallUserToken{}).Error
	return err
}
